package com.cqgc.dao;

import com.cqgc.domain.Barn;
import com.cqgc.domain.Harvest;
import com.cqgc.domain.PageHelper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BarnDao {
//    @Select("select * from barn where state = 1 or state = 2 limit #{currentPage},#{pageSize}")
//    List<Barn> findAll(PageHelper pageHelper);
//
//    @Select("select * from barn where state = 1 or state = 2")
//    List<Barn> findAllBarn();

    @Select("select * from barn  where state = 1 || state = 2 limit #{pageHelper.currentPage},#{pageHelper.pageSize}")
    List<Barn> findAll( @Param("pageHelper") PageHelper pageHelper);

    @Select("select * from barn where state = 1 || state = 2}")
    List<Barn> findAllBarn();

    @Select("select * from barn where bid = #{bid}")
    Barn findBarnByBid(int bid);

//    @Select("select * from barn where hid = #{hid}")
//    Barn findBarnByHid(int hid);

    @Update("update barn set bname = #{barn.bname} , lan = #{barn.lan} , er = #{barn.er} , yvjing = #{barn.yvjing}  " +
            "where bid = #{barn.bid}")
    int editBarn(@Param("barn") Barn barn);

    @Insert("insert into barn values(null,#{barn.lan},#{barn.er},#{barn.yvjing},#{barn.bname},1)")
    int addBarn(@Param("barn") Barn barn);

    @Update("update barn set state = 0 where bid = #{barn.bid}")
    int deleteBarn(@Param("barn") Barn barn);

    @Update("update barn set state = 2 where bid = #{barn.bid}")
    int banBarn(@Param("barn") Barn barn);
}
